package com.aop.proxy.ribbon;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;

@RestController
public class HelloCtl {
    @Autowired
    RestTemplate  restTemplate;
    private AtomicInteger count = new AtomicInteger();
    private AtomicInteger sleepCount = new AtomicInteger();
    @Autowired
    ServiceAFeignClient sfc;

    @RequestMapping(value="/ribbon/restem")
    public User ribbonClientCall(){
/*        User use =this.restTemplate.getForObject(
                "http://microservice-provider-user/ribbon/hello",
                User.class);*/
         User use = sfc.hi();
        return  use;

//        return "ribbon" + newCount + ": " + ThreadLocalRandom.current().nextInt(1000);
    }

    @RequestMapping(value="/ribbon/hellosleep")
    public String ribbonClientCallSleep(){
        try {
            Thread.sleep(1000 * 5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int newCount = sleepCount.incrementAndGet();
        return "ribbon sleep " + newCount + ": " + ThreadLocalRandom.current().nextInt(1000);
    }
}
